package com.example.easypoi.util;

import java.util.Calendar;
import java.util.Date;

/**
 * @description:
 * @author: 朱超
 * @createDate: 2021/12/26
 * @version: 1.0
 * @remark：根据日期计算星期
 */
public class WeekUtil {
    /**
     * 根据日期计算所在周的周一和周日
     * @param time 指定的日期
     */
    public static String convertWeekByDate(Date time) {
        String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(time);
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK)-1;
        if(dayOfWeek<0)dayOfWeek=0;
        return weekDays[dayOfWeek];
    }
    public static void main(String[] args) {
        System.out.println(convertWeekByDate(new Date()));
    }
}
